Repository navigation
Knowledge: connect a Bedrock knowledge base in place, searched live in your AWS account - #526
Merged
Merged
Conversation
…n the team's AWS account A base can now be connected in place instead of copied: an Amazon Bedrock knowledge base, searched with bedrock-agent-runtime Retrieve each time it is needed. Nothing is copied: no documents, passages or vectors. - Base.backend: Local (every existing record, unchanged) or Remote with the provider, the knowledge base's ARN, the region from the ARN, and how it is reached (the install's own role, or the team's CoderHelmLogReader role in that account with the team's private ID). - A Retriever trait beside Store and Embedder, taking the team. search() splits bases by backend, asks every connected base at once, and fuses each one's ranked list with the local vector and keyword lists. The per-file cap uses the document id; the question is embedded only when a local file is searched. A base that doesn't answer is named; the others still answer. - The Bedrock retriever: HYBRID search where the store supports it (found by the test search), no reranking; text, document id, title or S3 key, a metadata date and the original link become the hit; SourceKind::BedrockKb. - Connecting runs one test search first; failures come back in plain words (the role does not allow Retrieve, the install's boundary, a resource policy, an SCP, no such knowledge base, an unreachable endpoint), with the one-click CoderHelmLogReader update when the role only lacks the grant. - ReadKnowledgeBases in both log reader templates, on a KnowledgeBases parameter (ARNs, or all); the install's own role gets every knowledge base in its own account through the same update template. - The boundary gains bedrock:Retrieve in today's boundary only: it reaches an install through the admin-applied access stack (access.json), never through an update; the pinned parent boundary is unchanged. - Docs: self-host knowledge sources.
The fixture now comes from AWS's IAM policy simulator rather than a hand edit: the boundary allows bedrock:Retrieve, and the helper policy and release asset rows match the current build.
nambok
force-pushed
the
knowledge-connect-bedrock
branch
from
November 9, 2026 01:51
3cdb081 to
ca0d813
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1 of knowledge base import and connect: an existing Amazon Bedrock knowledge base can be connected in place. It is searched live with
bedrock-agent-runtimeRetrieve in the team's own AWS account whenever Chat or an agent needs it, and nothing is copied (no documents, passages or vectors). Every existing knowledge base is unchanged: it reads asLocaland behaves exactly as before.Because every consumer (planner, coder, reviewer, plan chat, plugins, brain chat and its citation registry) goes through
knowledge::search::search(), a connected base works everywhere at once.Changes
Search (
services/common/src/knowledge)Base.backend:Local(the default, so every stored record reads as before and is saved without the new field) orRemote { provider: BedrockKb, target: <KB ARN>, region (from the ARN), access, hybrid }.accessisInstall(a self-hosted install's own role) orAccount { account }(the team'sCoderHelmLogReaderrole in that account). The team's private ID is never stored on the base; it is read from Coderhelm's own record of the account at search time.Retrievertrait besideStoreandEmbedder, takingteam_idso isolation stays in the signature.search()splits the requested bases by backend. Local bases run as before. Every connected base is asked at once (in parallel with the local embed and index loads), and each answer joins the reciprocal rank fusion as one more ranked list.fuse()now takes any number of lists. The three-per-file cap keys on (base, document id). The Titan embedding runs only when a local file will be scored, so a search of only connected bases never embeds. A connected base that fails is reported inFound::unreachedand the others still answer; the search fails only when nothing could be searched, and it says why.remote.rs: ARN parsing, the Bedrock retriever (HYBRID on stores that support it, plain vector search where the store refuses it, found by the test search; no reranking), hits mapped from Retrieve results (content text, document id from metadata or the source address, title or S3 key as the place, a metadata date asas_of, the original page or the S3 console object as the link), andSourceKind::BedrockKbfor citations.refusal): AccessDenied becomes "The role in your account does not allow Retrieve on this knowledge base."; a permissions boundary refusal says the install's access stack hasn't been applied yet (the same sentence and fix as the Airflow read); a resource policy, an SCP, an unknown ARN, throttling, a failing vector store and an unreachable endpoint (with the VPC endpoint hint) each get their own sentence and fix. Account numbers and ARNs are stripped from AWS's text.Gateway
POST /api/knowledgetakesconnect: { provider: "bedrock_kb", target }. One test Retrieve runs before anything is saved. When the team's role only lacks the permission, the 400 carriesgrant: the one-clickCoderHelmLogReaderupdate for that account, naming every knowledge base the team connected there.GET /api/knowledge/bedrock: on a self-hosted install, the knowledge bases in its own account and region (bedrock:ListKnowledgeBases); everywhere, the team's connected AWS accounts and the ARNs already connected.POST /api/knowledge/:kb_id/check: one test search now, same answers.backend.search_knowledgetool use the Bedrock retriever; an unreached base is told to the model so it doesn't claim the base holds nothing.Access
live/aws.rs).ReadKnowledgeBases(bedrock:Retrieve,bedrock:GetDocumentContent) is in bothcoderhelm-log-reader.yamlandcoderhelm-log-reader-update.yaml, on a newKnowledgeBasesparameter (comma-separated ARNs, orallfor every knowledge base in the account, which also addsbedrock:ListKnowledgeBases). Empty, the default, grants nothing. No Bedrock resource policy is used: one naming Coderhelm's shared role would let any team that learned an ARN search it.log_reader::ABILITIESgains aknowledgeability markedchosen: it exists only for what a team names, so the role's live permission check never counts it missing. Update stacks for a set of knowledge bases are namedCoderHelmLogReaderUpdate-<id>-kb<hash>, so they never collide with the release's own.grantOwnAccountReadbuilds the install role's policy from the same update template, withKnowledgeBases = all(the install's own account only). CfnInclude keepsFn::If, soown-account-read.tsdecides the template's two conditions itself and fails the build on any condition it doesn't know.The permissions boundary, and why it changes only in the access stack
bedrock:Retrieveis added toBOUNDARY_SERVICESininfra/lib/access.ts. That is today's boundary, which since Self-host updates never wait on the deploy role or its boundary #519 reaches an install only through the admin-applied access stack (access.json): the parent keepsaccess-pinned.jsonbyte for byte, so no update ever waits on an AWS admin or changes a boundary.GetDocumentContentandListKnowledgeBaseswere already covered bybedrock:Get*andbedrock:List*.native-access.test.tsflagged the change, as designed.ACCESS_DOCS.boundaryis set to the new sha256, and a new test proves the pinned boundary still refuses Retrieve while today's (inaccess.json) allows it.ACCESS_DOCS.Docs:
docs/self-host/knowledge-sources.mdgets a section on connecting in place, who searches it, the one admin step, private networks and who sees what.Verification
cargo fmt --check,cargo clippy -p common -p gateway -p worker --all-targets -- -D warnings: clean.cargo test -p common -p gateway -p worker: 1582, 765 and 1408 passed. New unit tests use a fakeRetriever(no AWS calls): a remote list fused with local ones by rank only, Bedrock's order kept, the per-document cap per base, no embedding when only connected bases are searched (one when a local file is added), team isolation (another team's base id never reaches the retriever; the same id is asked as the asking team), an AccessDenied translated into plain words and the search failing with the base's name when nothing else could answer, ARN parsing, every refusal kind, access selection, the hit mapping, the update link and stack name, and the base JSON and refusals in the gateway.infra:npm test155 passed;cfn-lint infra/cfn/*.yamlclean.infra/test/fixtures/native-sim.json: regenerated withinfra/scripts/deploy-role-sim.py --native(AWS's IAM policy simulator, read-only calls). Its boundary allowsbedrock:Retrieve; the helper policy and one release asset row also caught up with the current build. 3204 (action, resource) pairs: 3140 allowed, 16 implicit deny, 48 explicit deny; 57 runtime rows.documentIdis not a field of this SDK'sKnowledgeBaseRetrievalResult(aws-sdk-bedrockagentruntime 1.125), so the document id comes from the metadata (x-amz-bedrock-kb-document-id, else the source URI).